import AsyncStorage from '@react-native-async-storage/async-storage';

/**
 *
 * @param {string} key
 * @param {string} value
 * @returns {Promise}
 */
export function setStorage(key, value) {
  return AsyncStorage.setItem(key, JSON.stringify(value));
}

/**
 *
 * @param {string} key
 * @returns {Promise}
 */
export function getStorage(key) {
  return AsyncStorage.getItem(key)
    .then(value => {
      if (value && value !== '') {
        return JSON.parse(value);
      }
    })
    .catch(() => null);
}

export function removeStorage(key) {
  return AsyncStorage.removeItem(key);
}
